home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / areacode / areacode.frm < prev    next >
Text File  |  1995-09-06  |  7KB  |  227 lines

  1. VERSION 2.00
  2. Begin Form areacode 
  3.    Caption         =   "Area Code Lookup"
  4.    ClientHeight    =   2730
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1695
  7.    ClientWidth     =   7905
  8.    FontBold        =   -1  'True
  9.    FontItalic      =   0   'False
  10.    FontName        =   "MS Sans Serif"
  11.    FontSize        =   12
  12.    FontStrikethru  =   0   'False
  13.    FontUnderline   =   0   'False
  14.    Height          =   3135
  15.    Icon            =   AREACODE.FRX:0000
  16.    Left            =   1035
  17.    LinkMode        =   1  'Source
  18.    LinkTopic       =   "Form1"
  19.    ScaleHeight     =   2730
  20.    ScaleWidth      =   7905
  21.    Top             =   1350
  22.    Width           =   8025
  23.    Begin CommandButton Command1 
  24.       Caption         =   "Look Up Area Code"
  25.       Default         =   -1  'True
  26.       Height          =   375
  27.       Left            =   5640
  28.       TabIndex        =   6
  29.       Top             =   2160
  30.       Width           =   2055
  31.    End
  32.    Begin TextBox ac 
  33.       FontBold        =   -1  'True
  34.       FontItalic      =   0   'False
  35.       FontName        =   "MS Sans Serif"
  36.       FontSize        =   12
  37.       FontStrikethru  =   0   'False
  38.       FontUnderline   =   0   'False
  39.       Height          =   420
  40.       Left            =   1800
  41.       TabIndex        =   3
  42.       Top             =   360
  43.       Width           =   735
  44.    End
  45.    Begin Label ltime 
  46.       BorderStyle     =   1  'Fixed Single
  47.       FontBold        =   -1  'True
  48.       FontItalic      =   0   'False
  49.       FontName        =   "MS Sans Serif"
  50.       FontSize        =   12
  51.       FontStrikethru  =   0   'False
  52.       FontUnderline   =   0   'False
  53.       Height          =   375
  54.       Left            =   1800
  55.       TabIndex        =   1
  56.       Top             =   1560
  57.       Width           =   5895
  58.    End
  59.    Begin Label Label1 
  60.       Alignment       =   1  'Right Justify
  61.       Caption         =   "Time:"
  62.       FontBold        =   -1  'True
  63.       FontItalic      =   0   'False
  64.       FontName        =   "MS Sans Serif"
  65.       FontSize        =   12
  66.       FontStrikethru  =   0   'False
  67.       FontUnderline   =   0   'False
  68.       Height          =   255
  69.       Left            =   840
  70.       TabIndex        =   0
  71.       Top             =   1560
  72.       Width           =   735
  73.    End
  74.    Begin Label location 
  75.       BorderStyle     =   1  'Fixed Single
  76.       FontBold        =   -1  'True
  77.       FontItalic      =   0   'False
  78.       FontName        =   "MS Sans Serif"
  79.       FontSize        =   9.75
  80.       FontStrikethru  =   0   'False
  81.       FontUnderline   =   0   'False
  82.       Height          =   375
  83.       Left            =   1800
  84.       TabIndex        =   5
  85.       Top             =   960
  86.       Width           =   5895
  87.    End
  88.    Begin Label Label3 
  89.       Alignment       =   1  'Right Justify
  90.       Caption         =   "Location:"
  91.       FontBold        =   -1  'True
  92.       FontItalic      =   0   'False
  93.       FontName        =   "MS Sans Serif"
  94.       FontSize        =   12
  95.       FontStrikethru  =   0   'False
  96.       FontUnderline   =   0   'False
  97.       Height          =   255
  98.       Left            =   240
  99.       TabIndex        =   4
  100.       Top             =   960
  101.       Width           =   1335
  102.    End
  103.    Begin Label Label2 
  104.       Alignment       =   1  'Right Justify
  105.       Caption         =   "Area Code:"
  106.       FontBold        =   -1  'True
  107.       FontItalic      =   0   'False
  108.       FontName        =   "MS Sans Serif"
  109.       FontSize        =   12
  110.       FontStrikethru  =   0   'False
  111.       FontUnderline   =   0   'False
  112.       Height          =   255
  113.       Left            =   120
  114.       TabIndex        =   2
  115.       Top             =   360
  116.       Width           =   1455
  117.    End
  118. End
  119. Dim areacodes(256) As Integer   ' All the areacodes
  120. Dim timezones(256) As Integer   ' Timezones from GMT
  121. Dim areanames(256) As String    ' Name of the Area Codes
  122. Dim numac As Integer            ' # of areacodes
  123. Dim tzhere As Integer           ' Local time zone
  124. Dim tzformat As String          ' How we like time/dates formatted
  125.  
  126. Sub Command1_Click ()
  127. '
  128. '   This routine finds the area code the user has entered, displays the
  129. '   location and the time at that location.  No attempt is made to handle
  130. '   areacodes which are split across time zones or places that do not
  131. '   go onto daylight savings time with the rest of the nation...
  132. '
  133.     Dim i As Integer
  134.     Dim findac As Integer
  135.  
  136.     findac = Val(ac.text)               ' The current areacode as an integer
  137.  
  138. '   We mark the areacode the user entered as "selected", so that after
  139. '   we finish the user can just start typing in a new area code without
  140. '   having to delete the old one...
  141.  
  142.     ac.selstart = 0
  143.     ac.sellength = Len(ac.text)
  144.  
  145. '   Search ...
  146.     For i = 1 To numac
  147.         If (areacodes(i) = findac) Then
  148.             ' When we find the area code, update the location and local times...
  149.             location.caption = areanames(i)
  150.             ltime.caption = Format$(Now + TimeSerial(tzhere, 0, 0) - TimeSerial(timezones(i), 0, 0), tzformat)
  151.             Exit Sub
  152.         End If
  153.     Next i
  154.  
  155. '   We didn't find the area code! Beep, erase all text on the display,
  156. '   and open a message box to complain!
  157.  
  158.     Beep
  159.     ac.text = ""
  160.     location.caption = ""
  161.     ltime.caption = ""
  162.     ac.sellength = 0
  163.     MsgBox "Invalid Area Code"
  164.     
  165. End Sub
  166.  
  167. Sub Form_Load ()
  168. '
  169. '   When the form is first loaded, read in the area code database
  170. '
  171. loadac
  172.  
  173. End Sub
  174.  
  175. Sub loadac ()
  176. '
  177. '   This routine loads in the area code file, which is
  178. '   assumed to be called "ac.dat". The file contains
  179. '   two sections.  The first section contains two lines,
  180. '   the first being the local time zone (offset from GMT),
  181. '   and the second line holding the time/date format the user
  182. '   prefers.
  183. '
  184. '   The second section contains the list of area codes, one per
  185. '   line.  The format is areacode/GMT offset/name
  186. '
  187. Dim s1 As Integer, s2 As Integer                    ' Location of slashes in text
  188. Dim f1 As String, f2 As String, f3 As String        ' Fields of the text
  189.  
  190. mousepointer = 11                                   ' Say we're busy
  191.  
  192. Open "ac.dat" For Input As 1                        ' Open the database
  193.  
  194. Input #1, tzhere                                    ' Read local time zone
  195. Line Input #1, tzformat                             ' Read prefered format
  196.  
  197. On Error GoTo done
  198.  
  199. '   Read in the table of areacodes
  200.  
  201. For numac = 1 To 256
  202.     Line Input #1, l$
  203.  
  204.     '   First break the line into the three pieces (/ is delimeter)
  205.  
  206.     s1 = InStr(l$, "/")
  207.     s2 = InStr(s1 + 1, l$, "/")
  208.     f1 = Left$(l$, s1 - 1)
  209.     f2 = Mid$(l$, s1 + 1, s2 - (s1 + 1))
  210.     f3 = Mid$(l$, s2 + 1)
  211.  
  212.     '   Then, assign our arrays the pieces
  213.     areacodes(numac) = Val(f1)
  214.     timezones(numac) = Val(f2)
  215.     areanames(numac) = f3
  216.     Next numac
  217.  
  218. done:   Resume done2
  219. done2:
  220.     ' Decrement numac as it's past the end of the data
  221.     numac = numac - 1
  222.  
  223.     '   Say we're not busy anymore...
  224.     mousepointer = 0
  225. End Sub
  226.  
  227.